package com.boho.ecp.manage.member.service;

import java.sql.Connection;
import java.util.Date;

import cn.boho.framework.po.ComboPager;
import cn.boho.framework.po.POUtils;
import cn.boho.framework.po.Pager;

import com.boho.ecp.constant.Member;
import com.boho.ecp.manage.member.dao.MemberDao;
import com.boho.ecp.po.TMemberPO;
import com.boho.ecp.util.MD5Digester;

public class MemberService {

	/**
	 * 分页查询会员信息
	 * @param con
	 * @param pager
	 * @param account
	 * @return
	 * @throws Exception
	 */
	public static ComboPager queryTMemberByPager(Connection con, Pager pager, String account) throws Exception{
		return MemberDao.queryTMemberByPager(con, pager, account);
	}
	
	/**
	 * 更改会员状态
	 * @param con
	 * @param memberId
	 * @param status
	 * @param operator
	 * @throws Exception
	 */
	public static void updateMemberStatus(Connection con, Integer memberId, String status, Integer operatorId) throws Exception{
		TMemberPO cPO = new TMemberPO();
		TMemberPO vPO = new TMemberPO();
		cPO.setMemberId(memberId);
		vPO.setMemberStatus(status);
		vPO.setUpdateBy(operatorId.toString());
		vPO.setUpdateDate(new Date());
		POUtils.update(con, cPO, vPO, false);
	}
	
	/**
	 * 重置密码
	 * @param con
	 * @param memberId
	 * @param operatorId
	 * @throws Exception
	 */
	public static void resetPassword(Connection con, Integer memberId, Integer operatorId) throws Exception{
		TMemberPO cPO = new TMemberPO();
		TMemberPO vPO = new TMemberPO();
		cPO.setMemberId(memberId);
		vPO.setPassword(MD5Digester.digest("88888888"));
		vPO.setUpdateBy(operatorId.toString());
		vPO.setUpdateDate(new Date());
		POUtils.update(con, cPO, vPO, false);
	}
	
	/**
	 * 删除用户
	 * @param con
	 * @param memberId
	 * @param operatorId
	 * @throws Exception
	 */
	public static void deleteMember(Connection con, Integer memberId, Integer operatorId) throws Exception{
		TMemberPO cPO = new TMemberPO();
		TMemberPO vPO = new TMemberPO();
		cPO.setMemberId(memberId);
		vPO.setIsValid(Member.INVALID);
		vPO.setUpdateBy(operatorId.toString());
		vPO.setUpdateDate(new Date());
		POUtils.update(con, cPO, vPO, false);
	}
	
	/**
	 * 更新会员积分
	 * @param con
	 * @param memberId
	 * @param points
	 * @throws Exception
	 */
	public static void updateMemberPoint(Connection con, Integer memberId, Integer points) throws Exception{
		MemberDao.updateMemberPoint(con, memberId, points);
	}
	
	/**
	 * 修改会员信息
	 * @param con
	 * @throws Exception
	 */
	public static void updateMemberInfo(Connection con)throws Exception{
		
	}
}
